#include "Vector2.h"
#include <math.h>
#include "util/Helper.h"


using namespace Boon;


Vector2::Vector2(void)
	: x( .0f ),
	  y( .0f )
{

}

Boon::Vector2::Vector2( const float X, const float Y )
	: x( X ),
	  y( Y )
{

}

Boon::Vector2::Vector2( const Vector2& o )
	: x( o.x ),
	  y( o.y )
{

}

void Vector2::swap( Vector2& rhs )
{
	using std::swap;
	std::swap( this->x, rhs.x );
	std::swap( this->y, rhs.y );
}

Vector2& Boon::Vector2::operator=( Vector2 rhs )
{
	swap( rhs );
	return *this;
}

Vector2& Boon::Vector2::operator+( const Vector2& rhs )
{
	x += rhs.x;
	y *= rhs.y;
	return *this;
}

float Boon::Vector2::Magnitude() const
{
	return sqrt( x * x + y * y );
}

float Boon::Vector2::SqrMagnitude() const
{
	return x * x + y * y;
}

float Boon::Vector2::Angle( const Vector2& rhs ) const
{
	return atan2( y, x ) * RadiansToDegree;
}

float Boon::Vector2::Dot( const Vector2& rhs ) const
{
	return x * rhs.x + y * rhs.y;
}


void Boon::Vector2::Normalize()
{
	float mag = Magnitude();
	*this /= mag;
}

Vector2& Boon::Vector2::Normalized()
{
	Normalize();
	return *this;
}

Vector2 Boon::Vector2::operator*( const float value )
{
	Vector2 tmp(x, y);
	tmp *= value;
	return tmp;
}

Vector2& Boon::Vector2::operator*=( const float value )
{
	x *= value;
	y *= value;
	return *this;
}

Vector2 Boon::Vector2::operator/( const float value )
{
	Vector2 tmp(x, y);
	tmp /= value;
	return tmp;
}

Vector2& Boon::Vector2::operator/=( const float value )
{
	x /= value;
	y /= value;
	return *this;
}

Vector2 Vector2::Lerp( const Vector2& from, const Vector2& to, float t )
{
	Vector2 tmp;
	tmp.x = Boon::Lerp<float>( from.x, to.x, t );
	tmp.y = Boon::Lerp<float>( from.y, to.y, t );
	return tmp;
}


Vector2::~Vector2(void)
{

}

